require 'snmp'
include SNMP

module ComputersHelper
  
  def pingecho(host, timeout=5, service="echo")
    begin
      timeout(timeout) do
        s = TCPSocket.new(host, service)
        s.close
      end
    rescue Errno::ECONNREFUSED
      return true
    rescue Timeout::Error
      return false
    rescue
      return false
    end
    return true
  end
  module_function :pingecho
  
  def systemdes(host="localhost")  
    Manager.open(:host => host) do |manager|
      response = manager.get(["sysDescr.0", "sysName.0"])
      response.each_varbind do |vb|
          puts "#{vb.name.to_s}  #{vb.value.to_s}  #{vb.value.asn1_type}"
      end
    end
  end
  module_function :systemdes
  
  def freespace(host='localhost')
    Manager.open(:host => host) do |manager|
      response = manager.get(["sysDescr.0", "sysName.0"])
    end
  end
  
end
